<?
include_once("db.php");

$id = mysql_escape_string($_REQUEST['id']);

if ($_REQUEST['thumb'] == 'true')
	$thumb=true;
else
	$thumb=false;

if (is_numeric($id)) {
	
	if ($thumb) {
		$sql = "SELECT Datatype, Thumb AS data FROM Bilder WHERE ID=$id";
	} else {
		$sql = "SELECT Datatype, Bilde AS data FROM Bilder WHERE ID=$id";
	}

	$bildene = mysql_query($sql);

	if (mysql_num_rows($bildene)) {
		$bildet=mysql_fetch_assoc($bildene);

		$type = $bildet['Datatype'];
		if ($type=='image/jpeg')
			$suffix=".jpg";
		elseif($type=='image/gif')
			$suffix=".gif";
		elseif ($type=='image/png')
			$suffix=".png";
		else
			$suffix=substr($type, 5);

		header("Content-Type: ".$bildet['Datatype']);
		header("Content-Disposition: inline; filename=urv$id$suffix");

		echo $bildet['data'];
	}
}
?>
